import win32api
import win32con
import time
import ctypes
import random

# Hex code for keys is on https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes?redirectedfrom=MSDN

W = 0x57  # Up
A = 0x41  # Left
S = 0x53  # Down
D = 0x44  # Right

J = 0x4A  # LK
K = 0x4B  # MK
U = 0x55  # LP
I = 0x49  # MP

MapVirtualKey = ctypes.windll.user32.MapVirtualKeyA  # Virtual Hardware Mapping


def hurricane_destroy_parking_lot():
    win32api.keybd_event(S, MapVirtualKey(S, 0), 0, 0)
    time.sleep(0.7)
    win32api.keybd_event(W, MapVirtualKey(W, 0), 0, 0)
    win32api.keybd_event(J, MapVirtualKey(J, 0), 0, 0)
    time.sleep(0.1)
    win32api.keybd_event(W, MapVirtualKey(W, 0), win32con.KEYEVENTF_KEYUP, 0)
    win32api.keybd_event(S, MapVirtualKey(S, 0), win32con.KEYEVENTF_KEYUP, 0)
    win32api.keybd_event(J, MapVirtualKey(J, 0), win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.01)


def hundred_feet():
    time.sleep(0.05)
    win32api.keybd_event(S, MapVirtualKey(S, 0), 0, 0)
    time.sleep(0.05)
    win32api.keybd_event(D, MapVirtualKey(D, 0), 0, 0)
    time.sleep(0.05)
    win32api.keybd_event(S, MapVirtualKey(S, 0), win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.05)
    win32api.keybd_event(J, MapVirtualKey(J, 0), 0, 0)
    time.sleep(0.05)
    win32api.keybd_event(D, MapVirtualKey(D, 0), win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.05)
    win32api.keybd_event(J, MapVirtualKey(J, 0), win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.01)


def move_right():
    # Move Right
    win32api.keybd_event(D, MapVirtualKey(S, 0), 0, 0)
    time.sleep(0.2)
    win32api.keybd_event(D, MapVirtualKey(S, 0), win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.01)


def move_left():
    # Move left
    win32api.keybd_event(A, MapVirtualKey(S, 0), 0, 0)
    time.sleep(0.2)
    win32api.keybd_event(A, MapVirtualKey(S, 0), win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.01)


def move_up():
    # Move up
    win32api.keybd_event(W, MapVirtualKey(S, 0), 0, 0)
    time.sleep(10)
    win32api.keybd_event(W, MapVirtualKey(S, 0), win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.1)


def move_down():
    # Move down
    win32api.keybd_event(S, MapVirtualKey(S, 0), 0, 0)
    time.sleep(0.2)
    win32api.keybd_event(S, MapVirtualKey(S, 0), win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.01)


Action = [move_right, move_down, move_up, move_left, hundred_feet, hurricane_destroy_parking_lot]

if __name__ == '__main__':
    while True:
        move_up()
        time.sleep(0.1)